package handle

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"yk1/api/basic/config"
	__ "yk1/api/basic/proto"
	"yk1/api/request"
)

func Login(c *gin.Context) {
	var req request.LoginReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "参数验证失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Client.Login(c, &__.LoginReq{
		Mobile:   req.Mobile,
		Password: req.Password,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "登录失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "登录成功",
		"data": r,
	})

}

func UserDetails(c *gin.Context) {
	var req request.UserDetailsReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "参数验证失败",
			"data": err.Error(),
		})
		return
	}
	r, err := config.Client.UserDetails(c, &__.UserDetailsReq{
		Identity: req.Identity,
	})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "统计失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "统计成功",
		"data": r,
	})

}

func UserList(c *gin.Context) {
	r, err := config.Client.UserList(c, &__.UserListReq{})
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 400,
			"msg":  "用户列表展示失败",
			"data": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "用户列表展示成功",
		"data": r,
	})
}
